Expand description
View-Process implementation.
This implementation supports headed and headless apps in Windows, Linux and MacOS.
§Usage
First add this to your Cargo.toml
:
[dependencies]
zng = "0.6.2"
zng-view = "0.3.4"
Then call init
before any other code in main
to setup a view-process that uses
the same app executable:
use zng::prelude::*;
fn main() {
zng_view::init();
APP.defaults().run_window(|ctx| {
unimplemented!()
})
}
When the app is executed init
setup its startup and returns, run_window
gets called and
internally starts the view-process, using the init
setup. The current executable is started
again, this time configured to be a view-process, init
detects this and highjacks the process
never returning.
§Software Backend
The webrender/swgl
software renderer can be used as fallback when no native OpenGL 3.2 driver is available, to build it
the feature "software"
must be enabled (it is by default) and on Windows MSVC the clang-cl
dependency must be installed and
associated with the CC
and CXX
environment variables, if requirements are not met a warning is emitted and the build fails.
To install dependencies on Windows:
- Install LLVM (https://releases.llvm.org/) and add it to the
PATH
variable:
setx PATH %PATH%;C:\Program Files\LLVM\bin
- Associate
CC
andCXX
withclang-cl
:
setx CC clang-cl
setx CXX clang-cl
Note that you may need to reopen the terminal for the environment variables to be available (setx always requires this).
§Pre-built
There is a pre-built release of this crate, zng-view-prebuilt
, it works as a drop-in replacement
In the Cargo.toml
file:
zng-view-prebuilt = "0.1"
Then in the main.rs
file:
use zng_view_prebuilt as zng_view;
fn main() {
zng_view::init();
// APP.defaults().run ..
}
The pre-built crate includes the "software"
and "ipc"
features, in fact ipc
is required, even for running on the same process,
you can also configure where the pre-build library is installed, see the zng-view-prebuilt
documentation for details.
The pre-build crate does not support extensions
.
§API Extensions
This implementation of the view API provides one extension:
"zng-view.webrender_debug"
:{ flags: DebugFlags, profiler_ui: String }
, sets Webrender debug flags.- The
zng-wgt-webrender-debug
implements a property that uses this extension.
- The
You can also inject your own extensions, see the extensions
module for more details.
§Crate
This crate is part of the zng
project.
§Cargo Features
This crate provides 3 feature flags, 2 enabled by default.
§"ipc"
Enables pre-build and init as view-process.
If this is enabled all communication with the view is serialized/deserialized, even in same-process mode.
Enabled by default.
§"software"
Enables software renderer fallback.
If enabled and a native OpenGL 3.2 driver is not available the swgl
software renderer is used.
Enabled by default.
§"bundle_licenses"
Bundle third party licenses.
Needs cargo-about
and Internet connection during build.
Not enabled by default. Note that "view_prebuilt"
always bundles licenses.
Re-exports§
Modules§
- Extensions API
Functions§
- Runs the view-process server if called in the environment of a view-process.
- Like
init
but with custom API extensions. - Runs the view-process server in the current process and calls
run_app
to also run the app in the current process. Note thatrun_app
will be called in a different thread. - Like
run_same_process
but with custom API extensions.